package org.jeecg.modules.gis.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.DynamicTableNameInnerInterceptor;
import org.locationtech.jts.geom.GeometryFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

@Configuration
public class GisConfig {

    @Bean
    public GeometryFactory geometryFactory() {
        // 你可以在这里指定 SRID 或精度模型
        return new GeometryFactory(); // 默认构造函数（SRID=0）
    }
    @Bean
    public RestTemplate gisRestTemplate() {
        return new RestTemplate();
    }

    @Bean
    public MybatisPlusInterceptor pbfTableInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();

        DynamicTableNameInnerInterceptor dynamicInterceptor = new DynamicTableNameInnerInterceptor();

        dynamicInterceptor.setTableNameHandler((sql, tableName) -> {
            // 获取当前线程需要用的表名
            String dynamicName = DynamicTableContext.getTableName();
            // 如果没有动态表名，则使用默认
            return dynamicName != null ? dynamicName : tableName;
        });

        interceptor.addInnerInterceptor(dynamicInterceptor);
        return interceptor;
    }
}
